import React from 'react';
import ReactDOM from 'react-dom';

var DialogManager = React.createClass({
            getInitialState:()=>{
                return{
                    flag:0 ,
                    items:[]
                };
            },
            addDialog:function(id,component,props){
                this.state.items.push(
                    {
                        id: id,
                        component:component,
                        props: props
                    }
                );
                this.setState({
                    flag: this.flag++
                });
            },
            getDialogRef: function(id){
                return this.refs[id];
            },
            render:function(){
                return (
                    <div key={90}>
                        {this.state.items.map(renderItems)}
                    </div>
                )
            }
        });
        function renderItems(item, i){
            let props = item.props||{};
            props.ref = item.id;
            props.key = i;
            return React.createElement(item.component, props);
        };
    var dialogManager =  ReactDOM.render(<DialogManager/> ,document.getElementById("dialogManager"));
    module.exports = dialogManager;